﻿import QtQuick 2.0
import QtQuick.Particles 2.0

Item {
    id: root
    width: 300
    height: 300

    Connections{
        target: widget
        onSendKeyPress: {
            //            console.log("====",name)
            //            trailsNormal.enabled = true
        }
        onSendStop: {
            //            trailsNormal.enabled = false
        }
        onSend_mouse_position: {
            //            console.log("====",x,y)
            px = x
            py = y
        }
    }

    property real px: 0
    property real py: 0
    property real emitRateCount: 0

//    Behavior on px  {
//        NumberAnimation{ duration: 100 }
//    }
//    Behavior on py  {
//        NumberAnimation{ duration: 100 }
//    }

    //    Rectangle{
    //        anchors.fill: parent
    //        color: "transparent"
    //        border.color: "red"
    //        border.width: 1
    //    }

    MyPathAnim{
        id: myPathAnim1
        dir: -1
        dx: px
        dy: py
    }
    MyPathAnim{
        id: myPathAnim2
        dir: 1
        dx: px
        dy: py
    }

    ParticleSystem { id: sys1 }
    ImageParticle {
        system: sys1
        source: "qrc:/imamges/image/glowdot.png"
        color: "cyan"
        alpha: 0
        SequentialAnimation on color {
            loops: Animation.Infinite
            ColorAnimation {
                from: "cyan"
                to: "magenta"
                duration: 1000
            }
            ColorAnimation {
                from: "magenta"
                to: "blue"
                duration: 2000
            }
            ColorAnimation {
                from: "blue"
                to: "violet"
                duration: 2000
            }
            ColorAnimation {
                from: "violet"
                to: "cyan"
                duration: 2000
            }
        }
        colorVariation: 0.3
    }
    //! [0]
    Emitter {
        id: trailsNormal    //光标效果
        system: sys1
        enabled: false

        emitRate: 60
        lifeSpan: 1000

        y: root.height*4/5
        x: root.width/2

        velocity: PointDirection { x: -30; y: -100; xVariation: 50; yVariation: 80; }
        acceleration: PointDirection {xVariation: 0; yVariation: 0;}
        velocityFromMovement: 10

        size: 4
        sizeVariation: 2
    }

    Emitter {
        id: trailsNormal2   //鼠标效果
        system: sys1
        enabled: false

        emitRate: 500
        lifeSpan: 1000

        velocity: PointDirection { xVariation: 4; yVariation: 4; }
        acceleration: PointDirection {xVariation: 10; yVariation: 10;}
        velocityFromMovement: 2

        size: 16
        sizeVariation: 4
    }

    Emitter {
        id: trailsNormal3  //鼠标效果
        system: sys1
        enabled: true
        x: myPathAnim1.targetX
        y: myPathAnim1.targetY

        emitRate: 500
        lifeSpan: 2200

        velocity: PointDirection { xVariation: 4; yVariation: 4; }
        acceleration: PointDirection {xVariation: 4; yVariation: 4;}
        velocityFromMovement: 0

        size: 16
        sizeVariation: 4
    }
    Emitter {
        id: trailsNormal4  //鼠标效果
        system: sys1
        enabled: trailsNormal3.enabled
        x: myPathAnim2.targetX
        y: myPathAnim2.targetY

        emitRate: trailsNormal3.emitRate
        lifeSpan: trailsNormal3.lifeSpan


        velocity: PointDirection { xVariation: 4; yVariation: 4; }
        acceleration: PointDirection {xVariation: 4; yVariation: 4;}
        velocityFromMovement: 0

        size: 16
        sizeVariation: 4
    }
}
